#include "Image.h"
#include "TextureManager.h"
#include "ReportError.h"
#include "Factory.h"
Image::Image()
{

}

void Image::Draw()
{
	TheTextureManager::Instance()->DrawTexture(m_texPath);

	glBegin(GL_QUADS);
	//counter clockwise winding 
	glTexCoord2f(0.0f, 1.0f); //coord for points
	glVertex3f((m_pos.X - 1.0f), (m_pos.Y - 1.0f), 0); //UVs
//	glVertex2f((m_pos.X - 1.0f), (m_pos.Y - 1.0f)); //UVs

	glTexCoord2f(1.0f, 1.0f); //coord for points
	glVertex3f((m_pos.X - 1.0f) + m_dimensions.X, (m_pos.Y - 1.0f), 0); //UVs
//	glVertex2f((m_pos.X - 1.0f) + m_dimensions.X, (m_pos.Y - 1.0f)); //UVs

	glTexCoord2f(1.0f, 0.0f); //coord for points
	glVertex3f((m_pos.X - 1.0f) + m_dimensions.X, 
		(m_pos.Y - 1.0f) + m_dimensions.Y, 0); //UVs
//	glVertex2f((m_pos.X - 1.0f) + m_dimensions.X, 
//			   (m_pos.Y - 1.0f) + m_dimensions.Y); //UVs

	glTexCoord2f(0.0f, 0.0f); //coord for points
	glVertex3f((m_pos.X - 1.0f), (m_pos.Y - 1.0f) + m_dimensions.Y, 0); //UVs
//	glVertex2f((m_pos.X - 1.0f), (m_pos.Y - 1.0f) + m_dimensions.Y); //UVs
	glEnd();
}

bool Image::Load(File* const f)
{
	if(!f->GetString(&m_texPath))
	{
		ReportError("Can't find filepath for GUIObject: Image. File missing:" + m_texPath);
	}

	return true;
}

const char* Image::GetTypeName()
{
	return "Image";
}

GUIObject* CreateNewImage()
{
	return new Image;
}

static bool gui = TheGUIObjectFactory::Instance()->AddToMap("Image", CreateNewImage);